LEADTOOLS Medical (Leadtools.Dicom assembly)

GetValue<T>(DicomElement,T) Method

Show in webframe
Example 







specifies the type of the value to return
an item in the data set
a value of type T that is returned if the actual value cannot be retrieved.
Returns the value of a DICOM element
Syntax
public T GetValue<T>( 
   DicomElement element,
   T defaultValue
)
'Declaration
 
Public Overloads Function GetValue(Of T)( _
   ByVal element As DicomElement, _
   ByVal defaultValue As T _
) As T
'Usage
 
Dim instance As DicomDataSet
Dim element As DicomElement
Dim defaultValue As T
Dim value As T
 
value = instance.GetValue(Of T)(element, defaultValue)
public T GetValue<T>( 
   DicomElement element,
   T defaultValue
)

            

            
 function Leadtools.Dicom.DicomDataSet.GetValue``1(DicomElement,``0)( 
   element ,
   defaultValue 
)
public:
T^ GetValuegeneric<typename T>
( 
   DicomElement^ element,
   T^ defaultValue
) 

Parameters

element
an item in the data set
defaultValue
a value of type T that is returned if the actual value cannot be retrieved.

Type Parameters

T
specifies the type of the value to return

Return Value

a value of type T that is the value of the DICOM element
Remarks
For information on this method, see GetValue.
Example
Copy Code  
Imports Leadtools
Imports Leadtools.Dicom

''' 
Private Sub DicomDataSet_GetValueExample()
   Dim sMsg As String
   ' ***************************************************
   ' *** First
   ' *** Create some elements and set the values
   ' ***************************************************

   Dim ds As DicomDataSet = New DicomDataSet()
   ds.InsertElementAndSetValue(DicomTag.HighBit, 15)

   ' This is how you check to see if the element got added -- for simplicity, we only check the first time
   MessageBox.Show(ds.InsertElementAndSetValueResult.ToString())

   Dim names As String() = {"ORIGINAL", "PRIMARY"}
   ds.InsertElementAndSetValue(DicomTag.ImageType, names)

   ds.InsertElementAndSetValue(DicomTag.PhotometricInterpretation, DicomImagePhotometricInterpretationType.Rgb)
   ds.InsertElementAndSetValue(DicomTag.PatientBirthDate, Now)
   ds.InsertElementAndSetValue(DicomTag.PatientName, "John^Smith")


   ' ***************************************************
   ' *** Second
   ' *** Retrieve the element values
   ' ***************************************************

   ' Get an int value of an element by specifying a tag
   Dim highbit As Integer = ds.GetValue(Of Integer)(DicomTag.HighBit, 0)

   ' This is how you check to see if the element value was successfully retrieved
   MessageBox.Show(ds.GetValueResult.ToString())

   ' Get a list of strings value of an element by specifying a tag
   Dim imageType As List(Of String) = ds.GetValue(Of List(Of String))(DicomTag.ImageType, Nothing)

   sMsg = String.Format("Result: {0}" & Constants.vbLf & "Values:", ds.GetValueResult)
   For Each s As String In imageType
      sMsg = sMsg & Constants.vbLf & s
   Next s
   MessageBox.Show(sMsg)

   ' Get an enumeration value of an element by specifying a tag
   Dim p As DicomImagePhotometricInterpretationType = ds.GetValue(Of DicomImagePhotometricInterpretationType)(DicomTag.PhotometricInterpretation, _
                                                                                                              DicomImagePhotometricInterpretationType.Rgb)

   ' Get value of an element by specifying the element
   Dim element As DicomElement = ds.FindFirstElement(Nothing, DicomTag.PatientName, False)
   Dim name As String = ds.GetValue(Of String)(element, Nothing)
   MessageBox.Show(name)

   ' Another overload
   Dim defaultDateTime As DateTime = New DateTime()
   Dim dateTime As DateTime = ds.GetValue(Of DateTime)(Nothing, True, DicomTag.PatientBirthDate, defaultDateTime)
   MessageBox.Show(dateTime.ToString())
End Sub
using Leadtools;
using Leadtools.Dicom;

/// 
private void DicomDataSet_GetValueExample()
{
   string sMsg;
   // ***************************************************
   // *** First
   // *** Create some elements and set the values
   // ***************************************************

   DicomDataSet ds = new DicomDataSet();
   ds.InsertElementAndSetValue(DicomTag.HighBit, 15);

   // This is how you check to see if the element got added -- for simplicity, we only check the first time
   MessageBox.Show(ds.InsertElementAndSetValueResult.ToString());

   string[] names = { "ORIGINAL", "PRIMARY" };
   ds.InsertElementAndSetValue(DicomTag.ImageType, names);

   ds.InsertElementAndSetValue(DicomTag.PhotometricInterpretation, DicomImagePhotometricInterpretationType.Rgb);
   ds.InsertElementAndSetValue(DicomTag.PatientBirthDate, DateTime.Now);
   ds.InsertElementAndSetValue(DicomTag.PatientName, "John^Smith");


   // ***************************************************
   // *** Second
   // *** Retrieve the element values
   // ***************************************************

   // Get an int value of an element by specifying a tag
   int highbit = ds.GetValue<int>(DicomTag.HighBit, 0);

   // This is how you check to see if the element value was successfully retrieved
   MessageBox.Show(ds.GetValueResult.ToString());

   // Get a list of strings value of an element by specifying a tag
   List<string> imageType = ds.GetValue<List<string>>(DicomTag.ImageType, null);
   sMsg = string.Format("Result: {0}\nValues:", ds.GetValueResult);
   foreach (string s in imageType)
   {
      sMsg = sMsg + "\n" + s;
   }
   MessageBox.Show(sMsg);

   // Get an enumeration value of an element by specifying a tag
   DicomImagePhotometricInterpretationType p = ds.GetValue<DicomImagePhotometricInterpretationType>(DicomTag.PhotometricInterpretation, 
                                                                                                    DicomImagePhotometricInterpretationType.Rgb);

   // Get value of an element by specifying the element
   DicomElement element = ds.FindFirstElement(null, DicomTag.PatientName, false);
   string name = ds.GetValue<string>(element, null);
   MessageBox.Show(name);

   // Another overload
   DateTime defaultDateTime = new DateTime();
   DateTime dateTime = ds.GetValue<DateTime>(null, true, DicomTag.PatientBirthDate, defaultDateTime);
   MessageBox.Show(dateTime.ToString());
}
using Leadtools.Dicom.Constants;
using Leadtools;
using Leadtools.Dicom;

/// 
private void DicomDataSet_GetValueExample()
{
   string sMsg;
   // ***************************************************
   // *** First
   // *** Create some elements and set the values
   // ***************************************************

   DicomDataSet ds = new DicomDataSet();
   ds.InsertElementAndSetValue(DicomTagConstants.HighBit, 15);

   // This is how you check to see if the element got added -- for simplicity, we only check the first time
   Debug.WriteLine(ds.InsertElementAndSetValueResult.ToString());

   string[] names = { "ORIGINAL", "PRIMARY" };
   ds.InsertElementAndSetValue(DicomTagConstants.ImageType, names);

   ds.InsertElementAndSetValue(DicomTagConstants.PhotometricInterpretation, DicomImagePhotometricInterpretationType.Rgb);

   Calendar calendar = new Calendar();
   calendar.SetToNow();
   ds.InsertElementAndSetValue(DicomTagConstants.PatientBirthDate, calendar);
   ds.InsertElementAndSetValue(DicomTagConstants.PatientName, "John^Smith");


   // ***************************************************
   // *** Second
   // *** Retrieve the element values
   // ***************************************************

   // Get an int value of an element by specifying a tag
   DicomElement highBitElem = ds.FindFirstElement(null, DicomTagConstants.HighBit, true);
   int highbit = ds.GetIntValue(highBitElem, 0, 1)[0];

   // This is how you check to see if the element value was successfully retrieved
   Debug.WriteLine(ds.GetValueResult.ToString());

   // Get a list of strings value of an element by specifying a tag
   DicomElement imageTypeElement = ds.FindFirstElement(null, DicomTagConstants.ImageType, true);
   string imageType = ds.GetStringValue(imageTypeElement, 0);
   sMsg = string.Format("Result: {0}\nValues:", imageType);
   //foreach (string s in imageType)
   //{
   //   sMsg = sMsg + "\n" + s;
   //}
   Debug.WriteLine(sMsg);

   // Get an enumeration value of an element by specifying a tag -- this will be returned as as string
   {
      DicomElement elem = ds.FindFirstElement(null, DicomTagConstants.PhotometricInterpretation, true);

      // this value should be "RGB"
      string sPhotometricInterpretation = ds.GetStringValue(elem, 0);
      Debug.Assert(sPhotometricInterpretation == "RGB");

      //GetHashCode<DicomImagePhotometricInterpretationType>
      //DicomImagePhotometricInterpretationType p = (DicomImagePhotometricInterpretationType)val;
   }

   // Get value of an element by specifying the element
   {
      DicomElement element = ds.FindFirstElement(null, DicomTagConstants.PatientName, false);
      string name = ds.GetStringValue(element, 0);
      Debug.WriteLine(name);
   }

   // Another overload
   {
      DicomElement elem = ds.FindFirstElement(null, DicomTagConstants.PatientBirthDate, true);
      DicomDateValue date = ds.GetDateValue(elem, 0, 1)[0];
     // Debug.WriteLine(DicomDateValueHelper.to(date));
   }
}
using Leadtools;
using Leadtools.Dicom;
using Leadtools.Examples;

private void DicomDataSet_GetValueExample()
{
   string sMsg;
   // ***************************************************
   // *** First
   // *** Create some elements and set the values
   // ***************************************************

   DicomDataSet ds = new DicomDataSet();
   ds.InsertElementAndSetValue(DicomTag.HighBit, 15);

   // This is how you check to see if the element got added -- for simplicity, we only check the first time
   Debug.WriteLine(ds.InsertElementAndSetValueResult.ToString());

   string[] names = { "ORIGINAL", "PRIMARY" };
   ds.InsertElementAndSetValue(DicomTag.ImageType, names);

   ds.InsertElementAndSetValue(DicomTag.PhotometricInterpretation, DicomImagePhotometricInterpretationType.Rgb);
   ds.InsertElementAndSetValue(DicomTag.PatientBirthDate, DateTime.Now);
   ds.InsertElementAndSetValue(DicomTag.PatientName, "John^Smith");


   // ***************************************************
   // *** Second
   // *** Retrieve the element values
   // ***************************************************

   // Get an int value of an element by specifying a tag
   int highbit = ds.GetValue<int>(DicomTag.HighBit, 0);

   // This is how you check to see if the element value was successfully retrieved
   Debug.WriteLine(ds.GetValueResult.ToString());

   // Get a list of strings value of an element by specifying a tag
   List<string> imageType = ds.GetValue<List<string>>(DicomTag.ImageType, null);
   sMsg = string.Format("Result: {0}\nValues:", ds.GetValueResult);
   foreach (string s in imageType)
   {
      sMsg = sMsg + "\n" + s;
   }
   Debug.WriteLine(sMsg);

   // Get an enumeration value of an element by specifying a tag
   DicomImagePhotometricInterpretationType p = ds.GetValue<DicomImagePhotometricInterpretationType>(DicomTag.PhotometricInterpretation, DicomImagePhotometricInterpretationType.Rgb);

   // Get value of an element by specifying the element
   DicomElement element = ds.FindFirstElement(null, DicomTag.PatientName, false);
   string name = ds.GetValue<string>(element, null);
   Debug.WriteLine(name);

   // Another overload
   DateTime defaultDateTime = new DateTime();
   DateTime dateTime = ds.GetValue<DateTime>(null, true, DicomTag.PatientBirthDate, defaultDateTime);
   Debug.WriteLine(dateTime.ToString());
}
Imports Leadtools
Imports Leadtools.Dicom

Private Sub DicomDataSet_GetValueExample()
   Dim sMsg As String
   ' ***************************************************
   ' *** First
   ' *** Create some elements and set the values
   ' ***************************************************

   Dim ds As DicomDataSet = New DicomDataSet()
   ds.InsertElementAndSetValue(DicomTag.HighBit, 15)

   ' This is how you check to see if the element got added -- for simplicity, we only check the first time
   Debug.WriteLine(ds.InsertElementAndSetValueResult.ToString())

   Dim names As String() = { "ORIGINAL", "PRIMARY" }
   ds.InsertElementAndSetValue(DicomTag.ImageType, names)

   ds.InsertElementAndSetValue(DicomTag.PhotometricInterpretation, DicomImagePhotometricInterpretationType.Rgb)
   ds.InsertElementAndSetValue(DicomTag.PatientBirthDate, System.DateTime.Now)
   ds.InsertElementAndSetValue(DicomTag.PatientName, "John^Smith")

   ' ***************************************************
   ' *** Second
   ' *** Retrieve the element values
   ' ***************************************************

   ' Get an int value of an element by specifying a tag
   Dim highbit As Integer = ds.GetValue(Of Integer)(DicomTag.HighBit, 0)

   ' This is how you check to see if the element value was successfully retrieved
   Debug.WriteLine(ds.GetValueResult.ToString())

   ' Get a list of strings value of an element by specifying a tag
   Dim imageType As List(Of String) = ds.GetValue(Of List(Of String))(DicomTag.ImageType, Nothing)
   sMsg = String.Format("Result: {0}" & Constants.vbLf & "Values:", ds.GetValueResult)
   For Each s As String In imageType
      sMsg = sMsg & Constants.vbLf & s
   Next s
   Debug.WriteLine(sMsg)

   ' Get an enumeration value of an element by specifying a tag
      Dim p As DicomImagePhotometricInterpretationType = ds.GetValue(Of DicomImagePhotometricInterpretationType)(DicomTag.PhotometricInterpretation, _
                                                                                                                 DicomImagePhotometricInterpretationType.Rgb)

   ' Get value of an element by specifying the element
   Dim element As DicomElement = ds.FindFirstElement(Nothing, DicomTag.PatientName, False)
   Dim name As String = ds.GetValue(Of String)(element, Nothing)
   Debug.WriteLine(name)

   ' Another overload
   Dim defaultDateTime As DateTime = New DateTime()
   Dim dateTime As DateTime = ds.GetValue(Of DateTime)(Nothing, True, DicomTag.PatientBirthDate, defaultDateTime)
   Debug.WriteLine(dateTime.ToString())
End Sub
Requirements

Target Platforms

See Also

Reference

DicomDataSet Class
DicomDataSet Members
Overload List

 

 


Products | Support | Contact Us | Copyright Notices
© 2006-2014 All Rights Reserved. LEAD Technologies, Inc.

Leadtools.Dicom requires a Medical toolkit server license and unlock key. For more information, refer to: Imaging Pro/Document/Medical Features